package com.qf.fcy.youshare;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Window;
import com.qf.fcy.youshare.adapter.CommonFragmentAdapter;
import com.qf.fcy.youshare.fragment.TutorialImageFragment;
import com.qf.fcy.youshare.fragment.TutorialJumpFragment;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Alex[FR]
 * Date: 2015/2/4
 * Email: alex_fcy@163.com
 */

public class TutorialActivity extends FragmentActivity {
    public TutorialActivity() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_tutorial);

        // 保存已经显示过的信息，这样下次直接进入主界面
        SharedPreferences sp = getSharedPreferences(Constants.SP_APP_DATA, MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(Constants.SP_KEY_TUTORIAL, true);
        editor.commit();


        List<Fragment> list = new LinkedList<Fragment>();
        // TODO 添加 Fragment
        // 添加教程的第一页
        TutorialImageFragment fragment = new TutorialImageFragment();
        Bundle args = new Bundle();
        args.putInt(Constants.ARG_TUTORIAL_IMAGE_LAYOUT_ID, R.layout.fragment_tutorial_image_1);
        fragment.setArguments(args);
        list.add(fragment);

        // 添加教程的第二页
        fragment = new TutorialImageFragment();
        args = new Bundle();
        args.putInt(Constants.ARG_TUTORIAL_IMAGE_LAYOUT_ID, R.layout.fragment_tutorial_image_2);
        fragment.setArguments(args);
        list.add(fragment);

        // 添加教程的第三页
        fragment = new TutorialImageFragment();
        args = new Bundle();
        args.putInt(Constants.ARG_TUTORIAL_IMAGE_LAYOUT_ID, R.layout.fragment_tutorial_image_3);
        fragment.setArguments(args);
        list.add(fragment);

        // 添加教程的第四页
        list.add(new TutorialJumpFragment());

        ViewPager pager = (ViewPager) findViewById(R.id.tutorial_pager);
        // 设置 Adapter
        pager.setAdapter(new CommonFragmentAdapter(getSupportFragmentManager(), list));

    }
}